package com.sgcc.epri.dcloud.util;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.sgcc.epri.dcloud.pojo.TreeNode;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DateUtilMy {


    /**
     * 获取时间区间中的每一天
     * @param treeNode
     * @return
     */
    public static List<String> getDateList(TreeNode treeNode){
        List<String> list = new ArrayList<String>();
        DateTime parse = DateUtil.parse(treeNode.getCalStartTime());
        LocalDateTime start = LocalDateTimeUtil.parse(treeNode.getCalStartTime()+"T00:00:00");
        LocalDateTime end = LocalDateTimeUtil.parse(treeNode.getCalEndTime()+"T00:00:00");
        Duration between = LocalDateTimeUtil.between(start, end);
        long l = between.toDays();
        for (long i = 0; i <= l; i++) {
            Date newDate = DateUtil.offset(parse, DateField.DAY_OF_MONTH, (int) i);
            list.add(newDate.toString().substring(0, 10));
        }
        return list;
    }
}
